
package com.hc.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.hc.dao.INodesDao;
import com.hc.dao.IRoleAndNodesDao;
import com.hc.domain.Nodes;
import com.hc.domain.RoleAndNodes;
import com.hc.service.IRoleAndNodesService;
@Service("roleAndNodesService")
public class RoleAndNodesServiceImpl implements IRoleAndNodesService {
	@Resource
	private IRoleAndNodesDao roleAndNodesDao;
	@Resource
	private INodesDao nodesDao;

	@Override
	public RoleAndNodes getRoleAndNodeByRoleIdAndNodeId(int roleId, int nodeId) {
		return roleAndNodesDao.getRoleAndNodeByRoleIdAndNodeId(roleId,nodeId);
		
	}

	@Override
	public void updateOrSave(RoleAndNodes rn) {
		roleAndNodesDao.updateOrSave(rn);
	}

	@Override
	public void deleteRoleAndNodesAndChlidNode(Nodes n) {
		List<Nodes> nodes = nodesDao.getNodesByParentId(n.getId());
		if (nodes!=null&&nodes.size()>0){
			for (Nodes ns:nodes){
				roleAndNodesDao.deleteRoleAndNodes(ns);
			}
		}
		roleAndNodesDao.deleteRoleAndNodes(n);
	}

	@Override
	public void deleteRoleAndNodes(RoleAndNodes rn) {
		roleAndNodesDao.deleteRoleAndNodes(rn);
	}
}

